// 用户相关模型
export interface User {
  id: string;
  username: string;
  phone: string;
  email?: string;
  password_hash: string;
  avatar_url?: string;
  status: 'active' | 'inactive' | 'suspended';
  last_login_at?: Date;
  created_at: Date;
  updated_at: Date;
}

export interface UserProfile {
  user_id: string;
  birth_date?: Date;
  height?: number;
  weight?: number;
  gender?: 'male' | 'female' | 'other';
  timezone: string;
  preferences?: any;
  created_at: Date;
  updated_at: Date;
}

export interface RefreshToken {
  id: string;
  user_id: string;
  token_hash: string;
  expires_at: Date;
  device_info?: string;
  last_used_at?: Date;
  created_at: Date;
  updated_at: Date;
}

// 健康数据模型
export interface HealthData {
  id: string;
  user_id: string;
  record_date: Date;
  steps: number;
  distance: number;
  calories: number;
  active_minutes: number;
  heart_rate_data?: number[];
  avg_heart_rate?: number;
  max_heart_rate?: number;
  min_heart_rate?: number;
  stress_level?: number;
  data_source: string;
  synced_at?: Date;
  created_at: Date;
  updated_at: Date;
}

export interface SleepData {
  id: string;
  user_id: string;
  sleep_date: Date;
  bedtime: Date;
  sleep_start: Date;
  wake_time: Date;
  get_up_time: Date;
  total_duration: number;
  deep_sleep: number;
  light_sleep: number;
  rem_sleep: number;
  awake_duration: number;
  sleep_efficiency?: number;
  sleep_score?: number;
  wake_up_count: number;
  sleep_stages?: any;
  data_source: string;
  synced_at?: Date;
  created_at: Date;
  updated_at: Date;
}

export interface ExerciseRecord {
  id: string;
  user_id: string;
  exercise_type: string;
  start_time: Date;
  end_time: Date;
  duration: number;
  calories_burned: number;
  distance: number;
  avg_heart_rate?: number;
  max_heart_rate?: number;
  heart_rate_zones?: any;
  avg_pace?: number;
  gps_data?: any;
  performance_metrics?: any;
  data_source: string;
  synced_at?: Date;
  created_at: Date;
  updated_at: Date;
}

// LLM和分析模型
export interface LLMConfiguration {
  id: string;
  user_id: string;
  provider: 'qwen' | 'deepseek' | 'private';
  api_key_encrypted: string;
  endpoint_url?: string;
  model_config?: any;
  is_active: boolean;
  last_tested_at?: Date;
  connection_status: boolean;
  created_at: Date;
  updated_at: Date;
}

export interface AnalysisResult {
  id: string;
  user_id: string;
  analysis_type: 'sleep' | 'stress' | 'exercise' | 'general' | 'nutrition';
  analysis_date: Date;
  input_data: any;
  analysis_content: string;
  recommendations?: string[];
  health_score?: number;
  metrics?: any;
  llm_provider: string;
  model_version?: string;
  processing_time_ms?: number;
  status: 'pending' | 'completed' | 'failed';
  error_message?: string;
  created_at: Date;
  updated_at: Date;
}

export interface HealthGoal {
  id: string;
  user_id: string;
  goal_type: 'steps' | 'sleep' | 'weight' | 'exercise' | 'heart_rate';
  goal_name: string;
  description?: string;
  target_values: any;
  start_date: Date;
  end_date?: Date;
  frequency: 'daily' | 'weekly' | 'monthly';
  status: 'active' | 'completed' | 'paused' | 'cancelled';
  progress_percentage: number;
  milestones?: any;
  last_updated_at?: Date;
  created_at: Date;
  updated_at: Date;
}

// 同步记录模型
export interface SyncRecord {
  id: string;
  user_id: string;
  data_source: string;
  sync_type: 'full' | 'incremental';
  sync_start_time: Date;
  sync_end_time?: Date;
  status: 'in_progress' | 'completed' | 'failed';
  records_processed: number;
  records_success: number;
  records_failed: number;
  error_details?: string;
  sync_summary?: any;
  created_at: Date;
  updated_at: Date;
}

// 系统日志模型
export interface SystemLog {
  id: string;
  user_id?: string;
  log_level: 'debug' | 'info' | 'warn' | 'error';
  category: string;
  message: string;
  metadata?: any;
  request_id?: string;
  session_id?: string;
  ip_address?: string;
  user_agent?: string;
  created_at: Date;
  updated_at: Date;
}

// 请求/响应接口
export interface CreateUserRequest {
  username: string;
  phone: string;
  email?: string;
  password: string;
}

export interface LoginRequest {
  username: string;
  password: string;
}

export interface LoginResponse {
  user: Omit<User, 'password_hash'>;
  token: string;
  refreshToken: string;
  expiresIn: number;
}

export interface HealthDataSyncRequest {
  date: string;
  steps?: number;
  distance?: number;
  calories?: number;
  active_minutes?: number;
  heart_rate_data?: number[];
  stress_level?: number;
  data_source: string;
}

export interface SleepDataSyncRequest {
  sleep_date: string;
  bedtime: string;
  sleep_start: string;
  wake_time: string;
  get_up_time: string;
  total_duration: number;
  deep_sleep?: number;
  light_sleep?: number;
  rem_sleep?: number;
  awake_duration?: number;
  sleep_efficiency?: number;
  sleep_score?: number;
  wake_up_count?: number;
  sleep_stages?: any;
  data_source: string;
}

export interface LLMConfigRequest {
  provider: 'qwen' | 'deepseek' | 'private';
  api_key: string;
  endpoint_url?: string;
  model_config?: any;
}

export interface AnalysisRequest {
  analysis_type: 'sleep' | 'stress' | 'exercise' | 'general' | 'nutrition';
  date_range: {
    start_date: string;
    end_date: string;
  };
  include_recommendations?: boolean;
}

export interface ApiResponse<T = any> {
  success: boolean;
  data?: T;
  message?: string;
  error?: string;
  pagination?: {
    page: number;
    limit: number;
    total: number;
    totalPages: number;
  };
}